package com.ttflutter.tkvideodownloader.pay

import android.text.TextUtils
import com.alibaba.fastjson.JSONException
import com.android.billingclient.api.SkuDetails
import com.ttflutter.tkvideodownloader.TTT
import org.json.JSONObject

/**
 * @author Afra55
 * @date 2019-07-31
 * A smile is the best business card.
 */
data class GooSkuDetails(
    val mOriginalJson: String,
    val productId: String,
    val type: String,
    val price: String,
    val price_amount_micros: Long,
    val price_currency_code: String,
    val original_price: String,
    val original_price_micros: Long,
    val title: String,
    val description: String,
    val subscriptionPeriod: String,
    val freeTrialPeriod: String,
    val introductoryPrice: String,
    val introductoryPriceAmountMicros: Long,
    val introductoryPricePeriod: String,
    val introductoryPriceCycles: String,
    val iconUrl: String,
    val isRewarded: Boolean
) {
    override fun toString(): String {
        when(0){
            // catch TTT
            1 ->{
                val jsonObject: JSONObject;
                var data:String? = null
                var isClose = false
                var extra11 = 0
                var extra12 = 1
                var extra13 = 2
                var extra14 = 3
                var extra15 = 4
                var extra16 = 5
                var extra17 = 6
                var extra18 = 7
                var extra19 = 8
                var extra20 = 9
                var extra21 = 10
                var extra22 = 11
                var extra23 = 12
                var extra24 = 13
                var extra25 = 14
                var extra26 = 15
                try {
                    jsonObject = JSONObject()
                    data = jsonObject.getString("data")
                    isClose = jsonObject.getBoolean("isClose")
                    extra11 = jsonObject.getInt("extra11")
                    extra12 = jsonObject.getInt("extra12")
                    extra13 = jsonObject.getInt("extra13")
                    extra14 = jsonObject.getInt("extra14")
                    extra15 = jsonObject.getInt("extra15")
                    extra16 = jsonObject.getInt("extra16")
                    extra17 = jsonObject.getInt("extra17")
                    extra18 = jsonObject.getInt("extra18")
                    extra19 = jsonObject.getInt("extra19")
                    extra20 = jsonObject.getInt("extra20")
                    extra21 = jsonObject.getInt("extra21")
                    extra22 = jsonObject.getInt("extra22")
                    extra23 = jsonObject.getInt("extra23")
                    extra24 = jsonObject.getInt("extra24")
                    extra25 = jsonObject.getInt("extra25")
                    extra26 = jsonObject.getInt("extra26")
                } catch (e: JSONException) {
                    e.printStackTrace()
                }
                TTT.set(null, "", data)
            }
        }
        // catch TTT
        return "SkuDetails: $mOriginalJson"
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) {
            return true
        }
        if (other == null || javaClass != other.javaClass) {
            return false
        }

        val details = other as GooSkuDetails?

        return TextUtils.equals(mOriginalJson, details?.mOriginalJson)
    }

    override fun hashCode(): Int {
        return mOriginalJson.hashCode()
    }

    companion object {
        @JvmStatic
        fun cloneBySkuDetails(skuDetails: SkuDetails): GooSkuDetails {
            return GooSkuDetails(
                skuDetails.originalJson,
                skuDetails.sku,
                skuDetails.type,
                skuDetails.price,
                skuDetails.priceAmountMicros,
                skuDetails.priceCurrencyCode,
                skuDetails.originalPrice,
                skuDetails.originalPriceAmountMicros,
                skuDetails.title,
                skuDetails.description,
                skuDetails.subscriptionPeriod,
                skuDetails.freeTrialPeriod,
                skuDetails.introductoryPrice,
                skuDetails.introductoryPriceAmountMicros,
                skuDetails.introductoryPricePeriod,
                skuDetails.introductoryPriceCycles,
                skuDetails.iconUrl,
                skuDetails.isRewarded
            )
        }
    }
}